//package com.young.springdemo.config.shiro;
//
//import com.young.springdemo.service.director.Decorator;
//import org.apache.shiro.mgt.RememberMeManager;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.realm.Realm;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.CookieRememberMeManager;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.apache.shiro.web.servlet.Cookie;
//import org.apache.shiro.web.servlet.SimpleCookie;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.servlet.Filter;
//import java.util.LinkedHashMap;
//import java.util.Map;
//
//@Configuration
//public class ShiroConfigure {
//
//    @Bean
//    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
//        System.out.println("Shiro权限控制shiroFilter() 执行了....");
//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//        //设置securityManager
//        shiroFilterFactoryBean.setSecurityManager(securityManager);
//
//        //拦截器
//        Map<String, String> filterChainDefinitionMap = new LinkedHashMap();
//
//        //所有匿名用户均可访问到Controller层的该方法下
//        filterChainDefinitionMap.put("/login", "anon");
//        filterChainDefinitionMap.put("/logininfo", "anon");
//        filterChainDefinitionMap.put("/static/**", "anon");
//        //配置退出过滤器
//        filterChainDefinitionMap.put("/login/logout", "logout");
//        //经过认证才可以访问
//        filterChainDefinitionMap.put("/**", "authc");
//
//        //如果不设置默认会自动寻找web工程根目录下的/login.jsp  当前就不配置了  直接去找login.jsp
//        shiroFilterFactoryBean.setLoginUrl("/login");//配置后  输入/index会去访问login界面
//        //未授权页面
//        shiroFilterFactoryBean.setUnauthorizedUrl("/login");
//
//        //自定义拦截器
//        Map<String, Filter> filterMap = new LinkedHashMap<>();
//
//        shiroFilterFactoryBean.setFilters(filterMap);
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
//        return shiroFilterFactoryBean;
//    }
//
//    @Bean
//    public DefaultWebSecurityManager securityManager() {
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//
//        securityManager.setRealm(myShiroRealm());
//        securityManager.setRememberMeManager(rememberMeManager());
//        return securityManager;
//    }
//
//    @Bean
//    public MyShiroRealm myShiroRealm() {
//        return new MyShiroRealm();
//    }
//
//    @Bean
//    public CookieRememberMeManager rememberMeManager() {
//        CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
//        cookieRememberMeManager.setCookie(rememberberMeCookie());
//        return cookieRememberMeManager;
//    }
//
//    @Bean
//    public SimpleCookie rememberberMeCookie() {
//        System.out.println("remember cookie");
//        //这个参数是cookie的名称，对应前端的checkbox的name=rememberMe
//        SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
//        //记住我cookie生效时间1天 s
//        simpleCookie.setMaxAge(10800);//有效时长当前设置为3个小时 和Session有效时长一致
//        return simpleCookie;
//    }
//
//}
